@extends('admin.public.header')
@section('listcontent')
    <form class="layui-form">
    <div class="layui-form layuimini-form">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>短信通知设置</legend>
        </fieldset>
        <input type="hidden" name="id" value="{{$info->id ?? 0}}" />
        <tip>短信通知设置用于用户下单时，给指定手机号发送短信通知。</tip>
        <div class="layui-form-item">
            <label class="layui-form-label">开启短信提醒</label>
            <div class="layui-input-block">
                @foreach($SmsSettingModel->getSmsStatusArr() as $k=>$v)
                    <input type="radio" name="sms_status" value="{{$k}}" title="{{$v}}" @if($k == ($info->sms_status ?? 0))checked="" @elseif(!isset($info->sms_status) && $k==0)checked="" @endif>
                @endforeach
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">阿里云AccessKeyId</label>
            <div class="layui-input-block">
                <input type="text" name="accessKeyId" value="{{ $info->accessKeyId ?? '' }}" placeholder="请输入阿里云AccessKeyId" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">阿里云AccessKeySecret</label>
            <div class="layui-input-block">
                <input type="text" name="accessKeySecret" value="{{ $info->accessKeySecret ?? '' }}" placeholder="请输入阿里云AccessKeySecret" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">短信模板签名</label>
            <div class="layui-input-block">
                <input type="text" name="sign" value="{{ $info->sign ?? '' }}" placeholder="请输入短信模板签名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">接收短信手机号</label>
            <div class="layui-input-block">
                <input type="text" name="mobile" value="{{ $info->mobile ?? '' }}" placeholder="请输入手机号" class="layui-input">
                <tip>多个手机号请使用英文逗号,分隔</tip>
            </div>
        </div>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>订单下单提醒</legend>
        </fieldset>
        <tip>例如：模板内容:您有一条新的订单，订单号：20210727112830963760，请登录商城后台查看。</tip>
        <div class="layui-form-item">
            <label class="layui-form-label">模板名称</label>
            <div class="layui-input-block">
                <input type="text" name="tpl_order[name]" value="{{ $info['tpl_order']['name'] ?? '' }}" placeholder="请输入模板名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模板ID</label>
            <div class="layui-input-block">
                <input type="text" name="tpl_order[tpl]" value="{{ $info['tpl_order']['tpl'] ?? '' }}" placeholder="请输入模板ID" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模板变量</label>
            <div class="layui-input-block">
                <input type="text" name="tpl_order[msg]" value="{{ $info['tpl_order']['msg'] ?? '' }}" placeholder="请输入模板变量" class="layui-input">
                <tip>例如：模板内容: 您有一个新的订单，订单号：${order}，则只需填写order</tip>
            </div>
        </div>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>订单退款提醒</legend>
        </fieldset>
        <tip>例如：模板内容:您有一条新的退款订单，订单号：20210727112830963760，请登录商城后台查看。</tip>
        <div class="layui-form-item">
            <label class="layui-form-label">模板名称</label>
            <div class="layui-input-block">
                <input type="text" name="tpl_refund[name]" value="{{ $info['tpl_refund']['name'] ?? '' }}" placeholder="请输入模板名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模板ID</label>
            <div class="layui-input-block">
                <input type="text" name="tpl_refund[tpl]" value="{{ $info['tpl_refund']['tpl'] ?? '' }}" placeholder="请输入模板ID" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模板变量</label>
            <div class="layui-input-block">
                <input type="text" name="tpl_refund[msg]" value="{{ $info['tpl_refund']['msg'] ?? '' }}" placeholder="请输入模板变量" class="layui-input">
                <tip>例如：模板内容: 您有一条新的退款订单，订单号：${order}，则只需填写order</tip>
            </div>
        </div>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>发送手机验证码</legend>
        </fieldset>
        <tip>例如：模板内容:您的验证码为89757，请勿告知他人。</tip>
        <div class="layui-form-item">
            <label class="layui-form-label">模板名称</label>
            <div class="layui-input-block">
                <input type="text" name="tpl_code[name]" value="{{ $info['tpl_code']['name'] ?? '' }}" placeholder="请输入模板名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模板ID</label>
            <div class="layui-input-block">
                <input type="text" name="tpl_code[tpl]" value="{{ $info['tpl_code']['tpl'] ?? '' }}" placeholder="请输入模板ID" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模板变量</label>
            <div class="layui-input-block">
                <input type="text" name="tpl_code[msg]" value="{{ $info['tpl_code']['msg'] ?? '' }}" placeholder="请输入模板变量" class="layui-input">
                <tip>例如：模板内容: 您的验证码为${code}，请勿告知他人。，则只需填写code</tip>
            </div>
        </div>
        <div class="hr-line"></div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" id="saveBtn" lay-submit lay-filter="saveBtn">保存</button>
            </div>
        </div>

    </div>
    </form>
@endsection

@section('listscript')
    <script type="text/javascript">
        layui.use(['iconPickerFa', 'form', 'layer', 'upload', 'xmSelect'], function () {
            var iconPickerFa = layui.iconPickerFa,
                form = layui.form,
                layer = layui.layer,
                upload = layui.upload,
                xmSelect = layui.xmSelect,
                $ = layui.$;
            
            //监听提交
            form.on('submit(saveBtn)', function(data){
                $("#saveBtn").addClass("layui-btn-disabled");
                $("#saveBtn").attr('disabled', 'disabled');
                var loading = layer.msg('加载中..', {icon: 16,shade: 0.3,time: false});
                $.ajax({
                    url:'/admin/mall_setting/sms_setting',
                    type:'post',
                    data:data.field,
                    dataType:'JSON',
                    headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                    success:function(res){
                        layer.close(loading);  //返回数据关闭loading
                        if(res.code==0){
                            layer.msg(res.message,{icon: 1},function (){
                                location.reload();
                            });
                        }else{
                            layer.msg(res.message,{icon: 2});
                            $("#saveBtn").removeClass("layui-btn-disabled");
                            $("#saveBtn").removeAttr('disabled');
                        }
                    },
                    error:function (data) {
                        layer.msg(res.message,{icon: 2});
                        $("#saveBtn").removeClass("layui-btn-disabled");
                        $("#saveBtn").removeAttr('disabled');
                    }
                });
            });
        });
    </script>
@endsection